<?php

if (!defined('BASEPATH'))
    exit('No direct script access allowed');

class empleador extends CI_Controller {

    function __construct() {
        parent::__construct();
        $this->load->library('session');
        $this->load->model('MAdministrador');
        $this->load->model('MPostulante');
        $this->load->model('MEmpleador');
        $this->load->model('MCiudad');
        $this->load->model('MDisponibilidad');
        $this->load->model('MEspecialidad');
        $this->load->model('MEstadoPostulacion');
        $this->load->model('MEstadoPostulante');
        $this->load->model('MEstadoPostulanteSis');
        $this->load->model('MRegion');
        $this->load->model('MRol');
        $this->load->model('MMensaje');
        $this->load->model('MEvento');
        $this->load->model('MPostulacion');
        $this->load->library('javascript');
    }
    
        
    
    
//_______________________________________________________________________________________________________________________________________________________________    
//______CARGA FORMULARIO DE CREACION DE NUEVO EVENTO_________________________________________________________________________________________________________________________________________________________    
    
        public function CrearEvento() {
        if ($this->session->userdata('rol') == 'empleador') {
            $empleador = $this->MEmpleador->consultarempleador($this->session->userdata('rut'));
            $empleador->RUT_EMP = $this->session->userdata('rut');
            $this->session->set_userdata('nombre', $empleador->NOMBRES);
            $ciudades = $this->MCiudad->getCiudades();
            $this->load->view('Empleador/CrearEvento', array('empleador' => $empleador, 'nombre' => $this->session->userdata('nombre'), 'ciudades' => $ciudades));
        } else {
            $this->load->view('login.php');
        }
    }

//_______________________________________________________________________________________________________________________________________________________________    
//_______________________________________________________________________________________________________________________________________________________________    
     
    
    
//_______________________________________________________________________________________________________________________________________________________________    
//___________INSERTA NUEVO EVENTO EN LA BD A TRAVES DEL MODELO____________________________________________________________________________________________________________________________________________________    

   public function InsertarEvento() {
        if ($this->session->userdata('rol') == 'empleador') {
            $this->MEvento->InsertarEvento($_POST);
            
                $this->session->set_userdata('rol', 'empleador');
                $this->load->view('Empleador/FormularioBusqueda',array( 'nombre' => $this->session->userdata('nombre')));
            
        } else {
            $this->load->view('login.php');
        }
    }
//_______________________________________________________________________________________________________________________________________________________________    
//_______________________________________________________________________________________________________________________________________________________________    
    
//_______________________________________________________________________________________________________________________________________________________________    
//___________BORRA EL EVENTO EN LA BD ____________________________________________________________________________________________________________________________________________________    

   public function BorrarEvento() {
       $codigoevento = $_POST['CODIGO_EVENTO'];
        if ($this->session->userdata('rol') == 'empleador') {
            $this->MEvento->BorrarEvento($codigoevento);
            
            $eventos = $this->MEvento->Buscar();
            echo "Evento Eliminado";
            $this->load->view('Empleador/MisEventos', array('eventos' => $eventos,));
            
        } else {
            $this->load->view('login.php');
        }
    }
//_______________________________________________________________________________________________________________________________________________________________    
//_______________________________________________________________________________________________________________________________________________________________    
    
 
    
//_______________________________________________________________________________________________________________________________________________________________    
//______________CARGA BANDEJA DE MENSAJES DEL EMPLEADOR_________________________________________________________________________________________________________________________________________________    
    
   
    public function RedactarMensaje() {
        
        $rut = $_POST['RUT_POS'];
        $hora = date('H:i:s');
        $fecha = date('d-m-Y');
        
        if ($this->session->userdata('rol') == 'empleador') {
            $empleador = $this->MEmpleador->consultarempleador($this->session->userdata('rut'));
            $postulante = $this->MPostulante->consultarpostulante($rut);
            $this->load->view('Empleador/RedactarMensaje', array('empleador'=> $empleador,'postulante'=>$postulante,'hora'=>$hora,'fecha'=>$fecha, 'nombre' => $this->session->userdata('nombre')));
        } else {
            $this->load->view('login.php');
        }
    }
//_______________________________________________________________________________________________________________________________________________________________    
//_______________________________________________________________________________________________________________________________________________________________    
    
  
     
//_______________________________________________________________________________________________________________________________________________________________    
//____________INSERTA MENSAJE EN LA BD___________________________________________________________________________________________________________________________________________________    
    
     public function InsertarMensaje() {
         
        if ($this->session->userdata('rol') == 'empleador') {
            $this->MMensaje->InsertarMensaje($_POST);
            echo "Mensaje enviado";
            $this->load->view('Empleador/FormularioBusqueda', array('nombre' => $this->session->userdata('nombre')));
        } else {
            $this->load->view('login.php');
        }
    }
//_______________________________________________________________________________________________________________________________________________________________    
//_______________________________________________________________________________________________________________________________________________________________    
    
    
    
//_______________________________________________________________________________________________________________________________________________________________    
//_____________CARGA OPCIONES DE BUSQUEDA DE POSTULANTES__________________________________________________________________________________________________________________________________________________    
    
     public function FormularioBusqueda() {
        if ($this->session->userdata('rol') == 'empleador') {
            $empleador = $this->MEmpleador->consultarempleador($this->session->userdata('rut'));
            $empleador->RUT_EMP = $this->session->userdata('rut');
            $this->session->set_userdata('nombre', $empleador->NOMBRES);
            $this->load->view('Empleador/FormularioBusqueda', array('nombre' => $this->session->userdata('nombre')));
        } else {
            $this->load->view('login.php');
        }
    }     
//_______________________________________________________________________________________________________________________________________________________________    
//_______________________________________________________________________________________________________________________________________________________________    
    
 
    
//_______________________________________________________________________________________________________________________________________________________________    
//___________MUESTRA RESULTADO DE LA BUSQUEDA DE POSTULANTES____________________________________________________________________________________________________________________________________________________    

        public function BuscarPostulante() {
        if ($this->session->userdata('rol') == 'empleador') {
            $empleador = $this->MEmpleador->consultarempleador($this->session->userdata('rut'));
            $empleador->RUT_EMP = $this->session->userdata('rut');
            $this->session->set_userdata('nombre', $empleador->NOMBRES);
            $postulantes = $this->MPostulante->Buscar($_POST['especialidad']);
            $this->load->view('Empleador/MostrarBusqueda', array('postulantes' => $postulantes, 'empleador' => $empleador, 'nombre' => $this->session->userdata('nombre')));
        } else {
            $this->load->view('login.php');
        }
    }
//_______________________________________________________________________________________________________________________________________________________________    
//_______________________________________________________________________________________________________________________________________________________________    
 
      
    
//_______________________________________________________________________________________________________________________________________________________________    
//_____MOSTRAR TODOS LOS POSTULANTES REGISTRADOS__________________________________________________________________________________________________________________________________________________________    

     function MostrarTodos() {

        
        $todos = $this->MPostulante->Todos();
        $datos_vista = array('rs_todos' => $todos);
        $this->load->view('Empleador/Todos', $datos_vista);
    }   

    
//_______________________________________________________________________________________________________________________________________________________________    
//_______________________________________________________________________________________________________________________________________________________________    
 
    
    
//_______________________________________________________________________________________________________________________________________________________________    
//__________MUESTRA LOS EVENTOS REALIZADOS POR EL EMPLEADOR_____________________________________________________________________________________________________________________________________________________    

   public function miseventos() {
        if ($this->session->userdata('rol') == 'empleador') {
            $eventos = $this->MEvento->Buscar();
            $this->load->view('Empleador/MisEventos', array('eventos' => $eventos,));
        } else {
            $this->load->view('login.php');
        }
    }

//_______________________________________________________________________________________________________________________________________________________________    
//_______________________________________________________________________________________________________________________________________________________________    
    
//_______________________________________________________________________________________________________________________________________________________________    
//__________MUESTRA LOS MENSAJES ENVIADOS POR EL EMPLEADOR_____________________________________________________________________________________________________________________________________________________    

   public function MensajesEnviados() {
        if ($this->session->userdata('rol') == 'empleador') {
            $mensajes = $this->MMensaje->Buscar();
            $this->load->view('Empleador/MensajesEnviados', array('mensajes' => $mensajes,));
        } else {
            $this->load->view('login.php');
        }
    }

//_______________________________________________________________________________________________________________________________________________________________    
//_______________________________________________________________________________________________________________________________________________________________    

    
//_______________________________________________________________________________________________________________________________________________________________    
//__________MUESTRA TODOS LOS POSTULANTES INSCRITOS EN LOS EVENTOS_____________________________________________________________________________________________________________________________________________________    

   public function usuariosInscritos() {
        if ($this->session->userdata('rol') == 'empleador') {
            $registrados = $this->MPostulacion->BuscarRegistrados();
            $this->load->view('Prueba/Tablas', array('registrados' => $registrados));
        } else {
            $this->load->view('login.php');
        }
    }

//_______________________________________________________________________________________________________________________________________________________________    
//_______________________________________________________________________________________________________________________________________________________________    
    
//_______________________________________________________________________________________________________________________________________________________________    
//__________MUESTRA LOS POSTULANTES INSCRITOS, POR EVENTO_________________________________________________________________________________________________________________________________________________________    

   public function listaInscritos() {
       
        $codigoevento = $_POST['CODIGO_EVENTO'];
       
       
        if ($this->session->userdata('rol') == 'empleador') {
            $inscritos = $this->MPostulacion->listaInscritos($codigoevento);
            $especialidades = $this->MEspecialidad->getEspecialidades();
            $evento = $this->MEvento->consultarevento($codigoevento);
            $this->load->view('Empleador/Lista', array('inscritos' => $inscritos,'evento'=> $evento, 'especialidades' => $especialidades));
        } else {
            $this->load->view('login.php');
        }
    }

//_______________________________________________________________________________________________________________________________________________________________    
//_______________________________________________________________________________________________________________________________________________________________    

    
    
//_______________________________________________________________________________________________________________________________________________________________    
//______REALIZA CAMBIOS EN EVENTOS PUBLICADOS_________________________________________________________________________________________________________________________________________________________    
   
    public function UpdateEvento() {
        $this->MEvento->updateEvento($_POST);
        $eventos = $this->MEvento->Buscar();
        $this->load->view('Empleador/MisEventos', array('eventos' => $eventos,));   
    }
    
//_______________________________________________________________________________________________________________________________________________________________    
//_______________________________________________________________________________________________________________________________________________________________    

    
    
//_______________________________________________________________________________________________________________________________________________________________    
//_______TRAE DATOS DEL EMPLEADOR LOGUEADO PARA PODER ACTUALIZARLOS________________________________________________________________________________________________________________________________________________________    
 
    public function MostrarEmpleador() {
        if ($this->session->userdata('rol') == 'empleador') {
            $empleador = $this->MEmpleador->consultarempleador($this->session->userdata('rut'));
            $empleador->RUT_EMP = $this->session->userdata('rut');
            $this->session->set_userdata('nombre', $empleador->NOMBRES);
            $empleador->RUT_EMP = $this->session->userdata('rut');
            $this->load->view('Empleador/InicioEmpleadorr', array('empleador' => $empleador, 'nombre' => $this->session->userdata('nombre')));
        } else {
            $this->load->view('login.php');
        }
    }
//_______________________________________________________________________________________________________________________________________________________________    
//_______________________________________________________________________________________________________________________________________________________________    
    
    public function updateEmpleador() {
        if ($this->session->userdata('rol') == 'empleador') {
        $this->MEmpleador->updateEmpleador($_POST);
            $empleador = $this->MEmpleador->consultarempleador($this->session->userdata('rut'));
            $empleador->RUT_EMP = $this->session->userdata('rut');
            $this->session->set_userdata('nombre', $empleador->NOMBRES);
            $empleador->RUT_EMP = $this->session->userdata('rut');
            $this->load->view('Empleador/InicioEmpleadorr', array('empleador' => $empleador, 'nombre' => $this->session->userdata('nombre')));
        } else {
            $this->load->view('login.php');
        }   
    }

}

   





//_______________________________________________________________________________________________________________________________________________________________    
//________________CARGA FORMULARIO DE REGISTRO DEL EMPLEADOR_______________________________________________________________________________________________________________________________________________  
//    
//    public function FormularioEmpleador() {
//
//        $this->load->view('Empleador/RegistraEmpleador');
//    }
//_______________________________________________________________________________________________________________________________________________________________    
//_______________________________________________________________________________________________________________________________________________________________      

    
//_______________________________________________________________________________________________________________________________________________________________    
//_______________ACTUALIZA DATOS EMPLEADOR________________________________________________________________________________________________________________________________________________    
//    
//    
//_______________________________________________________________________________________________________________________________________________________________    
//_______________________________________________________________________________________________________________________________________________________________    

    
//_______________________________________________________________________________________________________________________________________________________________    
//_________________INSERTA UN NUEVO EMPLEADOR EN LA BD______________________________________________________________________________________________________________________________________________    
//    
//    public function InsertarEmpleador() {
//        $this->MEmpleador->IngresarEmpleador($_POST);
//
//        $this->load->view('Prueba/PruebaBD', array('mensaje' => $Mensaje, 'test' => 'Hola!'));
//    }

//_______________________________________________________________________________________________________________________________________________________________    
//_______________________________________________________________________________________________________________________________________________________________    
    

//_______________________________________________________________________________________________________________________________________________________________    
//_______________________________________________________________________________________________________________________________________________________________    

//        public function ModificarPerfilEmpleador() {
//
//        $this->load->view('Empleador/ModificarPerfilEmpleador');
//    }
    
//_______________________________________________________________________________________________________________________________________________________________    
//_______________________________________________________________________________________________________________________________________________________________    
    

//_______________________________________________________________________________________________________________________________________________________________    
//_______ELIMINA AL EMPLEADOR LOGUEADO________________________________________________________________________________________________________________________________________________________    
//   
//    public function EliminarEmpleador() {
//
//        $empleador = $this->MEmpleador->BorrarEmpleador($_POST['RUT']);
////            $this->load->view('Postulante/MostrarPostulante',array('postulante'=>$postulante));
//    }

//_______________________________________________________________________________________________________________________________________________________________    
//_______________________________________________________________________________________________________________________________________________________________    
